This notebook covers the basics of creating an event list object and carrying out various operations such as simulating time and energies, joining, storing and retrieving event lists.
Import some useful libraries.
In [1]:
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
Import some relevant stingray libraries.
In [2]:
from stingray.events import EventList
from stingray.lightcurve import Lightcurve
Given photon arrival times, an eventlist object can be created.
In [3]:
times = [0.5, 1.5, 2.5, 3.5]
Create event list object by passing arrival times as argument.
In [4]:
ev = EventList(times)
ev.time
Out[4]:
Event lists can be loaded from light curve, where the standard followed is as follows: as many events are created as the counts in the lightcurve at the time specified by time bins.
To demonstrate this, define a light curve.
In [5]:
times = np.arange(3)
counts = np.floor(np.random.rand(3)*5)
lc = Lightcurve(times, counts)
In [6]:
lc.time, lc.counts
Out[6]:
Now, eventlist can be loaded by calling static from_lc()
method.
In [7]:
ev = EventList.from_lc(lc)
ev.time
Out[7]:
Alternatively, event list can be simulated from light curve using acceptance rejection method.
In [8]:
ev = EventList()
ev.simulate_times(lc)
ev.time
Out[8]:
In [46]:
ev = EventList()
ev = ev.read('events.fits', 'fits')
ev.time[1:10]
Out[46]:
After simulating event list, the original light curve can be recovered. Let's demonstrate by creating a light curve.
In [9]:
times = np.arange(50)
counts = np.floor(np.random.rand(50)*50000)
lc = Lightcurve(times, counts)
Simulate an event list.
In [10]:
ev = EventList()
ev.simulate_times(lc)
Recover original light curve curve using to_lc()
method. Here, dt
defines time resolution, tstart
the starting time, and tseg
the total time duration.
In [11]:
lc_new = ev.to_lc(dt=1, tstart=-0.5, tseg=50)
In [12]:
plt.plot(lc.counts,'r-', lc_new.counts, 'g-')
plt.xlabel('Times')
plt.ylabel('Counts')
Out[12]:
As can be seen from the figure above, the recovered light curve is aligned with the original light curve.
In order to simulate energies, a spectral distribution needs to be passed.
In [139]:
spectrum = [[1, 2, 3, 4, 5, 6],[1000, 2040, 1000, 3000, 4020, 2070]]
In [140]:
ev = EventList(ncounts=10)
ev.simulate_energies(spectrum)
Two event lists can also be joined together.
In [141]:
ev1 = EventList(time=[1,2,3])
In [142]:
ev2 = EventList(time=[4,5])
In [143]:
ev = ev1.join(ev2)
ev.time
Out[143]:
IO in all major formats including pickle, hdf5, fits and ascii is supported.
Below is an example of retrieving event list from a fits file.
In [144]:
ev = EventList()
ev = ev.read('events.fits', 'fits')
ev.time[1:10]
Out[144]:
Alternatively, we can used hdf5 to store and later retrieve data.
In [145]:
ev.write('ev.hdf5', 'hdf5')
ev = ev.read('ev.hdf5', 'hdf5')
ev.time[1:10]
Out[145]: